//第十章的指针练习
#include <stdio.h>

void copy_arr(double ar[], double in[], int n);
void copy_ptr(double *ar2, double *in2, int n2);
void copy_ptrs(double *ar3, double *in3, double *n3);

int main(void)
{
	double source[5] = { 1.1,2.2,3.3,4.4,5.5 };
	double target1[5];
	double target2[5];
	double target3[5];
	copy_arr(target1, source, 5);
	copy_ptr(target2, source, 5);
	copy_ptrs(target3, source, source+5);
	return 0;
}

void copy_arr(double ar[], double in[], int n)//使用数组实现。
{
	int circul;
	for (circul = 0; circul <= n-1; circul++)
	{
		ar[circul] = in[circul];
		printf("arr %lf\n", ar[circul]);
	}
}

void copy_ptr(double* ar2, double* in2, int n2)//使用指针实现。
{
	int circul;
	for (circul = 0; circul <= n2-1; circul++)
	{
		*(ar2 + circul) = *(in2 + circul);
		printf("ptr %lf\n", *(ar2+circul));
	}
}

void copy_ptrs(double* ar3, double* in3, double*n3)//使用指针实现。最后一个元素后面的指针。
{
	int circul;
	int pr3;
	pr3 = n3 - in3-1;
	for (circul = 0; circul <=pr3; circul++)
	{
		*(ar3 + circul) = *(in3 + circul);
		printf("ptrs %lf\n", *(ar3+circul));
	}
}